class Solution
{
public:
    ListNode* removeNthFromEnd(ListNode* head, int n)
    {
        ListNode dummy{ 0, head };
        auto l = &dummy;
        auto r = &dummy;
        while (n--) r = r->next;
        while (r->next)
        {
            l = l->next;
            r = r->next;
        }
        auto t = l->next;
        l->next = l->next->next;
        delete t;
        return dummy.next;
    }
};